package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.pojo.vo.UserVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户人群业务相关
 */
@Tag(name = "用户人群管理")
@RestController
public class UserGroupController {

    private static final Logger log = LoggerFactory.getLogger(UserGroupController.class);
    @Autowired
    private UserGroupService userGroupService;
    @Operation(summary = "人群列表")
    @PostMapping("/admin/basic/userGroup/list")
        public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery userGroupQuery) throws BusinessException{
            PageResult<UserGroupVO> userGroupVoPage = userGroupService.pageGroupList(userGroupQuery);
            return new Result<>(userGroupVoPage);
    }

    @Operation(summary = "保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> saveGroup(@RequestBody UserGroupParam param) throws BusinessException {
        log.debug("保存人群数据入参:{}",param);
            userGroupService.saveGroup(param);
            return Result.success();
    }


    @Operation(summary = "删除人群")
    @PostMapping("/admin/basic/userGroup/deleteCrowd/{groupId}")
    public Result<Void> deleteCrowd(@PathVariable Integer groupId) throws BusinessException {
        log.debug("删除人群数据入参:{}",groupId);
        userGroupService.deleteGroup(groupId);
        return Result.success();
    }

    @Operation(summary = "人群详情")
    @PostMapping("/admin/basic/userGroup/detail/{groupId}")
    public Result<UserGroupVO> detail(@PathVariable Integer groupId) throws BusinessException {
        log.debug("根据id查询人群数据入参:{}",groupId);
        UserGroupVO userGroupVO = userGroupService.selectGroupById(groupId);
        return new Result<>(userGroupVO);
    }
}
